<?php
/**
 * KayPaste
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.opensource.org/licenses/bsd-license.php
 *
 * @category  KayPaste
 * @package   Models
 * @copyright Copyright (c) 2007-2008 Robin Skoglund (http://robinsk.net/)
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @author    Robin Skoglund
 */

/**
 * This class represents a user.
 * 
 * @category  KayPaste
 * @package   Models
 * @copyright Copyright (c) 2007-2008 Robin Skoglund (http://robinsk.net/)
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @author    Robin Skoglund
 */
class Kaypaste_User extends Doctrine_Record
{
    /**
     * Sets up table definition
     * 
     * @return void
     */
    public function setTableDefinition()
    {
        $this->setTableName('kaypaste__users');
        
        $this->option('collate', 'utf8_unicode_ci');
        $this->option('charset', 'utf8');
        $this->option('type', 'INNODB');

        // username
        $this->hasColumn('username', 'string', 16,
                         array(
                             'fixed' => false,
                             'primary' => true,
                             'notnull' => true,
                             'autoincrement' => false
                         ));

        // email address
        $this->hasColumn('email', 'string', 96,
                         array(
                             'fixed' => false,
                             'primary' => false,
                             'notnull' => true,
                             'autoincrement' => false,
                             'email' => true,
                             'notblank' => true,
                             'unique' => true
                         ));

        // password
        $this->hasColumn('password', 'string', 32,
                         array(
                             'fixed' => false,
                             'primary' => false,
                             'notnull' => true,
                             'autoincrement' => false
                         ));

        // real name
        $this->hasColumn('realname', 'string', 64,
                         array(
                             'fixed' => false,
                             'primary' => false,
                             'notnull' => true,
                             'autoincrement' => false
                         ));

        // confirmation id, used when user is created
        $this->hasColumn('confirmation', 'string', 32,
                         array(
                             'fixed' => false,
                             'primary' => false,
                             'notnull' => false,
                             'autoincrement' => false
                         ));
    }

    /**
     * Sets up model behaviour
     * 
     * @return void
     */
    public function setUp()
    {
        parent::setUp();
        
        $this->actAs('Timestampable');
        $this->actAs('SoftDelete');
    }
}
